package edu.iscas.appcheckclient.service.check;

import android.view.accessibility.AccessibilityNodeInfo;

import java.util.ArrayList;
import java.util.List;

public class CheckMenuListBuilder {

    private static void checkEnabled(List<String> list, AccessibilityNodeInfo nodeInfo){
        if(nodeInfo.isEnabled()){
            list.add("Enabled");
        }else{
            list.add("Not enabled");
        }
    }

    private static void checkFocus(List<String> list, AccessibilityNodeInfo nodeInfo){
        if(nodeInfo.isFocused()){
            list.add("Has Focus");
        }else{
            list.add("Not have focus");
        }
    }

    private static void checkClickable(List<String> list, AccessibilityNodeInfo nodeInfo){
        if(nodeInfo.isClickable()){
            list.add("Clickable");
        }else{
            list.add("Not clickable");
        }
    }

    private static void checkChecked(List<String> list, AccessibilityNodeInfo nodeInfo){
        if(nodeInfo.isChecked()){
            list.add("Checked");
        }else{
            list.add("Not Checked");
        }
    }

    public static List<String> buildList(AccessibilityNodeInfo nodeInfo){
        String className = nodeInfo.getClassName().toString();
        ArrayList<String> list = new ArrayList<>();
//        try {
//            Class<?> targetClass = Class.forName(className);
//            if(TextView.class.isAssignableFrom(targetClass)){
//                list.add();
//            }
//        } catch (ClassNotFoundException e) {
//            e.printStackTrace();
//        }
        switch (className) {
            case "android.widget.AnalogClock":
                list.add("Displayed");
                list.add("Completely Displayed");
                checkEnabled(list, nodeInfo);
                break;
            case "android.widget.AutoCompleteTextView":
                list.add("Displayed");
                list.add("Completely Displayed");
                checkEnabled(list, nodeInfo);
                checkFocus(list, nodeInfo);
                list.add("Matches text");
                list.add("Store text in var");
                checkClickable(list, nodeInfo);
                list.add("Support IME");
                break;
            case "android.widget.Button":
                list.add("Displayed");
                list.add("Completely Displayed");
                checkEnabled(list, nodeInfo);
                list.add("Matches text");
                list.add("Matches text part");
                list.add("Store text in var");
                checkClickable(list, nodeInfo);
                break;
            case "android.widget.CheckBox":
                list.add("Displayed");
                list.add("Completely Displayed");
                checkEnabled(list, nodeInfo);
                checkChecked(list, nodeInfo);
                checkClickable(list, nodeInfo);
                break;
            case "android.widget.CheckedTextView":
                list.add("Displayed");
                list.add("Completely Displayed");
                checkEnabled(list, nodeInfo);
                list.add("Matches text");
                list.add("Matches text part");
                list.add("Store text in var");
                checkChecked(list, nodeInfo);
                checkClickable(list, nodeInfo);
                break;
            case "android.widget.Chronometer":
                list.add("Displayed");
                list.add("Completely Displayed");
                checkEnabled(list, nodeInfo);
                break;
            case "android.widget.DigitalClock":
                list.add("Displayed");
                list.add("Completely Displayed");
                checkEnabled(list, nodeInfo);
                break;
            case "android.widget.EditText":
                list.add("Displayed");
                list.add("Completely Displayed");
                checkEnabled(list, nodeInfo);
                checkFocus(list, nodeInfo);
                list.add("Matches text");
                list.add("Matches text part");
                list.add("Store text in var");
                checkClickable(list, nodeInfo);
                list.add("Support IME");
                break;
            case "android.widget.ImageButton":
                //8
                list.add("Displayed");
                list.add("Completely Displayed");
                checkEnabled(list, nodeInfo);
                checkClickable(list, nodeInfo);
                break;
            case "android.widget.MultiAutoCompleteTextView":
                //9
                list.add("Displayed");
                list.add("Completely Displayed");
                checkEnabled(list, nodeInfo);
                checkFocus(list, nodeInfo);
                list.add("Matches text");
                list.add("Matches text part");
                list.add("Store text in var");
                checkClickable(list, nodeInfo);
                list.add("Support IME");
                break;
            case "android.widget.ProgressBar":
                //a
                list.add("Displayed");
                checkEnabled(list, nodeInfo);
                break;
            case "android.widget.QuickContactBadge":
                //b
                list.add("Displayed");
                checkEnabled(list, nodeInfo);
                checkClickable(list, nodeInfo);
                break;
            case "android.widget.RadioButton":
                //c
                list.add("Displayed");
                list.add("Completely Displayed");
                checkEnabled(list, nodeInfo);
                checkChecked(list, nodeInfo);
                checkClickable(list, nodeInfo);
                break;
            case "android.widget.RatingBar":
                //d
                list.add("Displayed");
                checkEnabled(list, nodeInfo);
                break;
            case "android.widget.SeekBar":
                //e
                list.add("Displayed");
                checkEnabled(list, nodeInfo);
                break;
            case "android.widget.Switch":
                //f
                list.add("Displayed");
                list.add("Completely Displayed");
                checkEnabled(list, nodeInfo);
                list.add("Matches text");
                list.add("Matches text part");
                list.add("Store text in var");
                checkChecked(list, nodeInfo);
                checkClickable(list, nodeInfo);
                break;
            case "android.widget.TextClock":
                //10
                list.add("Displayed");
                list.add("Completely Displayed");
                checkEnabled(list, nodeInfo);
                list.add("Matches text");
                list.add("Matches text part");
                list.add("Store text in var");
                break;
            case "android.widget.TextView":
                //11
                list.add("Displayed");
                list.add("Completely Displayed");
                checkEnabled(list, nodeInfo);
                list.add("Matches text");
                list.add("Matches text part");
                list.add("Store text in var");
                checkChecked(list, nodeInfo);
                checkClickable(list, nodeInfo);
                break;
            case "android.widget.ToggleButton":
                //12
                list.add("Displayed");
                list.add("Completely Displayed");
                checkEnabled(list, nodeInfo);
                checkClickable(list, nodeInfo);
                break;
            case "android.widget.ZoomButton":

                break;
            case "android.widget.AdapterViewFlipper":

                break;
            case "android.widget.ArrayAdapter":

                break;
            case "android.widget.CalendarView":

                break;
            case "android.widget.DatePicker":

                break;
            case "android.widget.DialerFilter":

                break;
            case "android.widget.ExpandableListView":

                break;
            case "android.widget.FrameLayout":

                break;
            case "android.widget.Gallery":

                break;
            case "android.widget.GridLayout":

                break;
            case "android.widget.GridView":

                break;
            case "android.widget.HorizontalScrollView":

                break;
            case "android.widget.ImageSwitcher":

                break;
            case "android.widget.ImageView":

                break;
            case "android.widget.LinearLayout":

                break;
            case "android.widget.ListView":

                break;
            case "android.widget.MediaController":

                break;
            case "android.widget.NumberPicker":

                break;
            case "android.widget.RadioGroup":

                break;
            case "android.widget.RelativeLayout":

                break;
            case "android.widget.ScrollView":

                break;
            case "android.widget.SearchView":

                break;
            case "android.widget.SlidingDrawer":

                break;
            case "android.widget.Space":

                break;
            case "android.widget.Spinner":

                break;
            case "android.widget.StackView":

                break;
            case "android.widget.TabHost":

                break;
            case "android.widget.TableLayout":

                break;
            case "android.widget.TableRow":

                break;
            case "android.widget.TabWidget":

                break;
            case "android.widget.TextSwitcher":

                break;
            case "android.widget.TimePicker":

                break;
            case "android.widget.TwoLineListItem":

                break;
            case "android.widget.VideoView":

                break;
            case "android.widget.ViewAnimator":

                break;
            case "android.widget.ViewFlipper":

                break;
            case "android.widget.ViewSwitcher":

                break;
            case "android.widget.ZoomControls":

                break;
        }
        
        list.add("Check everything");
        list.add("Cancel Check");

        return list;
    }
}
